//
//  HGGoodsCell.m
//  RedWinMall
//
//  Created by HeDianZhao on 2018/7/28.
//  Copyright © 2018年 HeDianZhao. All rights reserved.
//

#import "HGGoodsCell.h"
#import "HGGoodsModel.h"

@interface HGGoodsCell ()

@property (strong, nonatomic)UIImageView *goodsimage;

@property (strong, nonatomic)UILabel *goodsNameLabel;

@property (strong, nonatomic)UILabel *goodsMoenyLabel;

@property (strong, nonatomic)UILabel *sellLabel;

@end

@implementation HGGoodsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initSubViews];
    }
    return self;
}

- (void)setGoodModel:(HGGoodsModel *)goodModel {
    _goodModel = goodModel;
    
    [_goodsimage sd_setImageWithURL:kPhotoURL(goodModel.faceImg) placeholderImage:nil options:(SDWebImageRefreshCached)];
    _goodsNameLabel.text = goodModel.name;
    _goodsMoenyLabel.text = goodModel.rmbPrice;
    _sellLabel.text = [NSString stringWithFormat:@"已售: %ld件",goodModel.sold];
}


- (void)initSubViews {
    
    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头

    CGFloat margin = 15;
    
    _goodsimage = [[UIImageView alloc] init];
    _goodsimage.image = [UIImage imageNamed:@"jiazai"];
    _goodsimage.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:_goodsimage];
    
    [_goodsimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.offset(margin);
        make.size.mas_equalTo(CGSizeMake(114, 114));
    }];
    
    _goodsNameLabel = [[UILabel alloc] init];
    _goodsNameLabel.font = [UIFont systemFontOfSize:12];
    _goodsNameLabel.textColor = kColorText;
    _goodsNameLabel.text = @"拉菲庄园至尊红酒\n口感醇厚";
    [self.contentView addSubview:_goodsNameLabel];
    
    [_goodsNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsimage.mas_right).offset(margin);
        make.top.equalTo(self.goodsimage).offset(10);
    }];
    
    _goodsMoenyLabel = [[UILabel alloc] init];
    _goodsMoenyLabel.font = [UIFont systemFontOfSize:16];
    _goodsMoenyLabel.text = @"￥6888.00";
    [self.contentView addSubview:_goodsMoenyLabel];
    
    [_goodsMoenyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsNameLabel);
        make.centerY.equalTo(self.goodsimage);
    }];
    
    _sellLabel = [[UILabel alloc] init];
    _sellLabel.font = [UIFont systemFontOfSize:12];
    _sellLabel.textColor = kColorWithFloat(0x666666);
    _sellLabel.text = @"已售：6778件";
    
    [self.contentView addSubview:_sellLabel];
    
    [_sellLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsNameLabel);
        make.top.equalTo(self.goodsMoenyLabel.mas_bottom).offset(margin);
    }];
}

@end
